Repository navigation
Fix potential process-wide umask mixups - #1449
Conversation
sirosen
left a comment
There was a problem hiding this comment.
- Three cheers for the fix itself, in
src/! - Request for some added doc in test utilities.
- If we can find a way to reduce test duplication, I would like that. But if it seems impossible, we can set that aside.
| assert stat.S_IMODE(json_file.stat().st_mode) == 0o600 | ||
|
|
||
|
|
||
| @pytest.mark.xfail(IS_WINDOWS, reason="cannot set umask perms on Windows") |
There was a problem hiding this comment.
xfail or skip? I would have naively reached for a skip, so I'm curious if there's a particular benefit in having these tests as xfail that I should think about and learn.
There was a problem hiding this comment.
Keeping this as an xfail makes the code run, which gives useful feedback if this starts passing unexpectedly.
A skip would mean that we don't get that signal.
There was a problem hiding this comment.
Sure... I guess that's all there is to it? I was thinking "but it will never pass!"
I guess your point is that that's an assumption, and xfail gives us the power to verify it.
I'll think more about the cases in which I skip tests. Maybe I need to make a broader realignment.
| with open(json_file, "w", opener=JSONTokenStorage._owner_only_opener) as f: | ||
| f.write("data") | ||
| assert stat.S_IMODE(json_file.stat().st_mode) == 0o600 | ||
| assert json_file.read_text() == "data" |
There was a problem hiding this comment.
It reads to me like we have the same tests in duplicate for the current ("v2") token storage and the legacy storage. Are we comfortable simply removing the legacy testing path? Or can we do something to combine these?
I count, as it stands, four variants of test_..._leave_the_process_umask_alone. All are testing the same invariant, across four different classes.
It strikes me as rather a lot of not only identical physical lines, but a lot of identical ideas, so it's registering as something to improve.
| If the code under test serializes the writes, the second can never reach its | ||
| checkpoint while the first waits, so the first simply times out and carries on. | ||
| The order of events is then different, but nothing deadlocks. | ||
| """ |
There was a problem hiding this comment.
Can we add a little console block here to show demo usage? I really like this class, but it took a few minutes to read through usage sites and understand it.
We don't have to work with a real use-case, just something like...
# rephrase further as you see fit
controller = OverlappingWrites()
action1 = build_action1(callback=controller.first_checkpoint)
action2 = build_action2(callback=controller.second_checkpoint)
controller.run(action1, action2)So that it's clear that the OverlappingWrites object lifecycle wraps around the code under test.
6dde763 to
e0e6f73
Compare
Merging this PR will improve performance by 15.44%1 warning
Performance Changes
Tip Curious why performance improved? Comment Comparing |
sirosen
left a comment
There was a problem hiding this comment.
I think we could find ways to consolidate more of the tests, but I think this is at a good point for the simplicity-to-concision tradeoff.
Deprecated
FileTokenStorage.user_only_umask()andFileAdapter.user_only_umask()are deprecated and will be removed in version 5. (:pr:
NUMBER)They change the umask of the whole process,
which is not safe when other threads are running.
Fixed
All file-based token storage classes create files
with mode
0o600set directly, and do not change the process umask. (:pr:NUMBER)This avoids a thread safety issue that could cause I/O in other threads
to create files with an unexpected umask.